package aufgabe1;

import java.util.ArrayList;

public class AdjacencyMatrix extends AdjacencyStructure {

	protected AdjacencyMatrix(Graph g) {
		super(g);

	}

	@Override
	public void print() {
		super.print();

		int[][] _matrix = _g.getMatrix();

		System.out.println("________");

		for (int k = 0; k <= _g.getVertices().size(); k++) {
			System.out.print(k + "\t");
		}
		System.out.println();

		for (int i = 1; i < _matrix.length; i++) {
			System.out.print(i + "\t");

			for (int j = 1; j < _matrix[i].length; j++) {
				System.out.print(_matrix[i][j] + "\t");
			}
			System.out.println();
		}

	}

	/**
	 * just nodes to which the actual node points are Neighbours
	 */
	@Override
	public ArrayList<Vertice> getNeighbours(int key) {
		ArrayList<Vertice> ns = new ArrayList();
		if (!(key < _g.getMatrix().length)) {
			return ns;
		}
		for (int i = 1; i < _g.getMatrix().length; i++) {

			int k = _g.getMatrix()[key][i];

			if (k != 0) {
				ns.add(_g.getVertice(i));
			}
		}
		return ns;
	}

}
